[ASAN] lib: Squash various leaks in library and commandline
authorColin Walters <walters@verbum.org>
Fri, 18 Nov 2016 15:33:50 +0000 (10:33 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 21 Nov 2016 16:34:06 +0000 (16:34 +0000)
The pull one is the most likely to affect users.  Otherwise mostly
just cleaning up `-fsanitize=address`.

Closes: #587
Approved by: jlebon

12 files changed:
src/libostree/ostree-metalink.c
src/libostree/ostree-repo-libarchive.c
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo-static-delta-compilation-analysis.c
src/libostree/ostree-repo-static-delta-core.c
src/libostree/ostree-sepolicy.c
src/libostree/ostree-sysroot-cleanup.c
src/libostree/ostree-sysroot-upgrader.c
src/ostree/ot-builtin-export.c
src/ostree/ot-builtin-fsck.c
src/ostree/ot-remote-builtin-add-cookie.c
src/ostree/ot-remote-builtin-delete-cookie.c

index b850818daafc94e5d0eab68034c00a8775dde8cf..ad3d5bf9406e1f2230362a19fd8956d5d553b624 100644 (file)
@@ -632,6 +632,9 @@ _ostree_metalink_request_sync (OstreeMetalink        *self,
   if (mainctx)
     g_main_context_pop_thread_default (mainctx);
   g_clear_object (&request.metalink);
+  g_clear_pointer (&request.verification_sha256, g_free);
+  g_clear_pointer (&request.verification_sha512, g_free);
+  g_clear_pointer (&request.last_metalink_error, g_free);
   g_clear_pointer (&request.urls, g_ptr_array_unref);
   g_clear_pointer (&request.parser, g_markup_parse_context_free);
   return ret;
index 3a58d1068851dbc3d9b34d5a8594a3af4b99c5dd..02a1180acd4dca805d05d979d61812a18ffa22fa 100644 (file)
@@ -943,7 +943,10 @@ ostree_repo_write_archive_to_mtree (OstreeRepo                *self,
   ret = TRUE;
  out:
   if (a)
-    (void)archive_read_close (a);
+    {
+      (void)archive_read_close (a);
+      (void)archive_read_free (a);
+    }
   return ret;
 #else
   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
index 8c18052f1835d214e83d2fdd47055b83fba39f9a..9e960792980c480aad84e83e22db8818e2826f41 100644 (file)
@@ -1982,7 +1982,7 @@ _ostree_repo_remote_new_fetcher (OstreeRepo  *self,
     g_autofree char *cookie_file = g_strdup_printf ("%s.cookies.txt",
                                                     remote_name);
 
-    jar_path = g_build_filename (g_file_get_path (self->repodir), cookie_file,
+    jar_path = g_build_filename (gs_file_get_path_cached (self->repodir), cookie_file,
                                  NULL);
 
     if (g_file_test(jar_path, G_FILE_TEST_IS_REGULAR))
@@ -2061,7 +2061,7 @@ fetch_mirrorlist (OstreeFetcher  *fetcher,
                   GError        **error)
 {
   gboolean ret = FALSE;
-  char **lines = NULL;
+  g_auto(GStrv) lines = NULL;
   g_autofree char *contents = NULL;
   SoupURI *mirrorlist = NULL;
   g_autoptr(GPtrArray) ret_mirrorlist =
@@ -2367,7 +2367,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
   const char *dir_to_pull = NULL;
   g_autofree char **dirs_to_pull = NULL;
   g_autofree char **refs_to_fetch = NULL;
-  char **override_commit_ids = NULL;
+  g_autofree char **override_commit_ids = NULL;
   GSource *update_timeout = NULL;
   gboolean disable_static_deltas = FALSE;
   gboolean require_static_deltas = FALSE;
index c19905916ff4cb54b0f133c937f29abb49bc1c91..2b9b006fdf6b39520be58249bdc0d149a5ffc776 100644 (file)
@@ -243,7 +243,7 @@ _ostree_delta_compute_similar_objects (OstreeRepo                 *repo,
 {
   gboolean ret = FALSE;
   g_autoptr(GHashTable) ret_modified_regfile_content =
-    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_ptr_array_unref);
+    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   g_autoptr(GPtrArray) from_sizes = NULL;
   g_autoptr(GPtrArray) to_sizes = NULL;
   guint i, j;
index 0b0d70672d5652093b3e1211a7834dbc7c740275..133ab016ee822b09e7546a3b725944bacd48a114 100644 (file)
@@ -880,7 +880,9 @@ _ostree_repo_static_delta_dump (OstreeRepo                    *self,
                                OT_VARIANT_MAP_TRUSTED, &delta_superblock, error))
     goto out;
 
-  g_print ("%s\n", g_variant_print (delta_superblock, 1));
+  { g_autofree char *variant_string = g_variant_print (delta_superblock, 1);
+    g_print ("%s\n", variant_string);
+  }
 
   g_print ("Delta: %s\n", delta_id);
   { const char *endianness_description;
index 8e49428f76384787a214c56a630dc2a123389a49..fa2647046790ca9e6aa38d66c2ff16baf6a66853 100644 (file)
@@ -258,7 +258,7 @@ initable_init (GInitable     *initable,
   g_autoptr(GFileInputStream) filein = NULL;
   g_autoptr(GDataInputStream) datain = NULL;
   gboolean enabled = FALSE;
-  char *policytype = NULL;
+  g_autofree char *policytype = NULL;
   const char *selinux_prefix = "SELINUX=";
   const char *selinuxtype_prefix = "SELINUXTYPE=";
 
@@ -352,7 +352,7 @@ initable_init (GInitable     *initable,
           goto out;
         }
 
-      self->selinux_policy_name = g_strdup (policytype);
+      self->selinux_policy_name = g_steal_pointer (&policytype);
       self->selinux_policy_root = g_object_ref (etc_selinux_dir);
     }
 
index 862d8154054052541e4e8fc8208d1a212fc8c270..2a78d2ce5a8cccd1062ae3252716f41d3197626d 100644 (file)
@@ -491,7 +491,7 @@ prune_repo (OstreeRepo    *repo,
 
   if (freed_space > 0)
     {
-      char *freed_space_str = g_format_size_full (freed_space, 0);
+      g_autofree char *freed_space_str = g_format_size_full (freed_space, 0);
       g_print ("Freed objects: %s\n", freed_space_str);
     }
 
index b0061c8778d8cdeae919ec7b5b703703bbba05e1..447bd82bed74ec524a2e01461c090c93876cea75 100644 (file)
@@ -105,6 +105,7 @@ parse_refspec (OstreeSysrootUpgrader  *self,
   csum = g_key_file_get_string (self->origin, "origin", "override-commit", NULL);
   if (csum != NULL && !ostree_validate_checksum_string (csum, error))
     goto out;
+  g_clear_pointer (&self->override_csum, g_free);
   self->override_csum = g_steal_pointer (&csum);
 
   ret = TRUE;
index 5b84d1ab51a235c5735214e1879c1c5ee20f6dc9..db4dbc313014b34dd5519695948c0da68671f82c 100644 (file)
@@ -67,7 +67,7 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
   g_autoptr(GFile) subtree = NULL;
   g_autofree char *commit = NULL;
   g_autoptr(GVariant) commit_data = NULL;
-  struct archive *a;
+  struct archive *a = NULL;
   OstreeRepoExportArchiveOptions opts = { 0, };
 
   context = g_option_context_new ("COMMIT - Stream COMMIT to stdout in tar format");
@@ -154,6 +154,10 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
   
   ret = TRUE;
  out:
+#ifdef HAVE_LIBARCHIVE  
+  if (a)
+    archive_write_free (a);
+#endif
   if (context)
     g_option_context_free (context);
   return ret;
index 5afa435f521a378bb0fa0c509b6aba35b8a12992..9809ad294eae8901a53701d76312c9f18aadc9da 100644 (file)
@@ -287,7 +287,7 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
           if (opt_add_tombstones)
             {
               GError *local_error = NULL;
-              const char *parent = ostree_commit_get_parent (commit);
+              g_autofree char *parent = ostree_commit_get_parent (commit);
               if (parent)
                 {
                   g_autoptr(GVariant) parent_commit = NULL;
index 439e7503c8c08535aefa28dd07e892b59e3de920..f1657bb890716e46b815e68bc5096dac1c3de963 100644 (file)
@@ -68,7 +68,7 @@ ot_remote_builtin_add_cookie (int argc, char **argv, GCancellable *cancellable,
   value = argv[5];
 
   cookie_file = g_strdup_printf ("%s.cookies.txt", remote_name);
-  jar_path = g_build_filename (g_file_get_path (repo->repodir), cookie_file, NULL);
+  jar_path = g_build_filename (gs_file_get_path_cached (repo->repodir), cookie_file, NULL);
 
   jar = soup_cookie_jar_text_new (jar_path, FALSE);
 
@@ -80,5 +80,7 @@ ot_remote_builtin_add_cookie (int argc, char **argv, GCancellable *cancellable,
   /* jar takes ownership of cookie */
   soup_cookie_jar_add_cookie (jar, cookie);
 
+  if (context)
+    g_option_context_free (context);
   return TRUE;
 }
index 9f05a564ea79e0219a4b4fd3aeaff43815cefe77..df65b277b5183b2f406fc6a40d5f3eab28aff720 100644 (file)
@@ -67,7 +67,7 @@ ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellabl
   cookie_name = argv[4];
 
   cookie_file = g_strdup_printf ("%s.cookies.txt", remote_name);
-  jar_path = g_build_filename (g_file_get_path (repo->repodir), cookie_file, NULL);
+  jar_path = g_build_filename (gs_file_get_path_cached (repo->repodir), cookie_file, NULL);
 
   jar = soup_cookie_jar_text_new (jar_path, FALSE);
   cookies = soup_cookie_jar_all_cookies (jar);
@@ -92,5 +92,7 @@ ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellabl
   if (!found)
     g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cookie not found in jar");
 
+  if (context)
+    g_option_context_free (context);
   return found;
 }